import regex

def getContent(path):
    map={};
    with open(path, 'r', encoding="utf-8") as file:
        linelist = file.readlines()
        flag=1;
        plugin="";
        version="";
        splitV="<ExactVersion=\"";
        splitP="<PlugIn>"
        for line in linelist:
            line=line.replace(" ","").replace("\n","");
            if flag==1 and line.startswith(splitV):
                version=line.replace(splitV,"").replace("\">","");
                flag=2;
            elif flag==2  and line.startswith(splitP):
                plugin=line.replace(splitP,"").replace("</PlugIn>","")
                flag=1;
                map[plugin]=version;
        return map;

def outPutDiff(map1,map2):
    keyCache=[];
    for key in map1:
        if map2.__contains__(key):
           if not map1[key]==map2[key]:
                print("plugin {} left version is {} right version is {}".format(key,map1[key],map2[key]))
        else:
            print("left hava plugin {} which right do'nt contain".format(key))
            keyCache.append(key);
    for key in map2:
        if not map1.__contains__(key):
            print("right  hava plugin {} which left do'nt contain".format(key))
if __name__ == '__main__':
    leftPath="C:\\PLC\\CODESYS3.5.17\\CODESYS 3.5.17.20\\CODESYS\\Profiles\\CODESYS V3.5 SP17 Patch 3.profile.xml";
    rightPath="C:\\PLC\\CODESYS3.5.17\\CODESYS 3.5.17.20\\CODESYS\\Profiles\\CODESYS V3.5 SP17 Patch 2.profile.xml";
    leftMap=getContent(leftPath);
    rightPath=getContent(rightPath);
    outPutDiff(leftMap,rightPath);
